# -*- coding: utf-8 -*-
"""
# @created on : 9月 2021/9/15 00:53
# @author     : kevin
# @file       : create_report.py
# @software   : PyCharm
# @project    : auto_interface_test


@license: (C) Copyright 2019-2025, Corporation Limited.
@desc:
"""
import time
import os
from BeautifulReport import BeautifulReport
from common.logger import Logger
from utils.operation_path import OperationPath


class CreatReport:
    """
    使用BeautifulReport生成测试报告
    """
    def __init__(self):
        self.log = Logger()
        self.path = OperationPath()
        p_path = self.path.get_current_path()
        self.report_path = os.path.join(p_path, 'report', time.strftime("%Y%m%d"))
        self.path.check_path(self.report_path)
        self.report_file_name = time.strftime("%Y%m%d%H%M%s") + '_report.html'

    def creat_report(self, suit):
        """
        根据suit的执行生成测试报告
        :param suit: unitest suit
        :return:
        """

        result = BeautifulReport(suit)
        result.report(filename=self.report_file_name, description='测试报告', report_dir=self.report_path)
        self.log.logger('info', f'生成测试报告{self.report_file_name}!')

    def get_report_file(self):
        return os.path.join(self.report_path, self.report_file_name)

